﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Petshop.Backend.DTO;

namespace Petshop.Backend.Data
{
    static class Factory
    {
        public static Account From(AccountInfo accountInfo)
        {
            var account = new Account();
            account.Addr1 = accountInfo.Address.Address1;
            account.Addr2 = accountInfo.Address.Address2;
            account.City = accountInfo.Address.City;
            account.Country = accountInfo.Address.Country;
            account.Email = accountInfo.Email;
            account.FavCategory = accountInfo.Category;
            account.FirstName = accountInfo.Address.FirstName;
            account.LangPref = accountInfo.Language;
            account.LastName = accountInfo.Address.LastName;
            account.MyListOpt = accountInfo.IsShowFavorites ? 1 : 0;
            account.Password = accountInfo.Password;
            account.Phone = accountInfo.Address.Phone;
            account.State = accountInfo.Address.State;
            account.UserId = accountInfo.UserId;
            account.Zip = accountInfo.Address.Zip;
            return account;
        }
        public static Account Update(Account account, AccountInfo accountInfo)
        {
            account.Addr1 = accountInfo.Address.Address1;
            account.Addr2 = accountInfo.Address.Address2;
            account.City = accountInfo.Address.City;
            account.Country = accountInfo.Address.Country;
            account.Email = accountInfo.Email;
            account.FavCategory = accountInfo.Category;
            account.FirstName = accountInfo.Address.FirstName;
            account.LangPref = accountInfo.Language;
            account.LastName = accountInfo.Address.LastName;
            account.MyListOpt = accountInfo.IsShowFavorites ? 1 : 0;
            account.Password = accountInfo.Password;
            account.Phone = account.Phone;
            account.State = accountInfo.Address.State;
            account.UserId = accountInfo.UserId;
            account.Zip = accountInfo.Address.Zip;
            return account;
        }
        public static Order From(OrderInfo orderInfo)
        {
            var order = new Order();
            order.UserId = orderInfo.UserId;
            order.BillAddr1 = orderInfo.BillingAddress.Address1;
            order.BillAddr2 = orderInfo.BillingAddress.Address2;
            order.BillCity = orderInfo.BillingAddress.City;
            order.BillCountry = orderInfo.BillingAddress.Country;
            order.BillState = orderInfo.BillingAddress.State;
            order.BillToFirstName = orderInfo.BillingAddress.FirstName;
            order.BillToLastName = orderInfo.BillingAddress.LastName;
            order.BillZip = orderInfo.BillingAddress.Zip;
            order.ShipAddr1 = orderInfo.BillingAddress.Address1;
            order.ShipAddr2 = orderInfo.ShippingAddress.Address2;
            order.ShipCity = orderInfo.ShippingAddress.City;
            order.ShipCountry = orderInfo.ShippingAddress.Country;
            order.ShipState = orderInfo.ShippingAddress.State;
            order.ShipToFirstName = orderInfo.ShippingAddress.FirstName;
            order.ShipToLastName = orderInfo.ShippingAddress.LastName;
            order.ShipZip = orderInfo.ShippingAddress.Zip;
            order.CardType = orderInfo.CreditCard.CardType;
            order.CreditCard = orderInfo.CreditCard.CardNumber;
            order.ExprDate = orderInfo.CreditCard.CardExpiration;
            order.OrderDate = DateTime.Now;
          

            foreach (var item in orderInfo.LineItems)
            {
                   order.LineItems.Add(new LineItem() {   Quantity = item.Quantity, LineNum = item.Line, ItemId = item.ItemId , UnitPrice = item.Price }) ;
            }
            order.TotalPrice = orderInfo.OrderTotal;
            return order;
        }
    }


   
}
